
package com.yimixian.app.dao;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

public class YMXDaoService {
    private static YMXDaoService sInstance;

    public static YMXDaoService getInstance() {
        if (sInstance == null) {
            sInstance = new YMXDaoService();
        }
        return sInstance;
    }

    public void saveTest() {
        YmxDBModel model = new YmxDBModel();
        model.setContent("Content");
        model.setTitle("title");
        model.save();
    }

    public void saveAll() {
        List<YmxDBModel> List = new ArrayList<>();
        // TODO:add data
        DataSupport.saveAll(List);
    }

    public void Update(YmxDBModel update) {
        update.setTitle("hello update");
        update.update(update.getId());
    }

    public void delete() {
        DataSupport.delete(YmxDBModel.class, 3);
    }

    public void delete(YmxDBModel model) {
        if (model.isSaved()) {
            model.delete();
        }
    }

    public List<YmxDBModel> get() {
        List<YmxDBModel> list = DataSupport.where("id > ?", "0").limit(20).offset(0)
                .find(YmxDBModel.class);
        return list;
    }
}
